package org.example.service.impl.article;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.dao.article.ArticleDao;
import org.example.dto.wechat.GetBatchgetMaterialParamsDTO;
import org.example.entity.article.ArticleEntity;
import org.example.service.article.ArticleService;
import org.example.service.utils.PageUtils;
import org.springframework.stereotype.Service;

@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleDao, ArticleEntity> implements ArticleService {

    @Override
    public PageUtils<ArticleEntity> getBatchgetMaterial(GetBatchgetMaterialParamsDTO paramsDTO) {
        PageUtils pageUtils=null;
        try {
            long pageSize = paramsDTO.getPageSize();
            long currPage = paramsDTO.getCurrPage();
            Page<ArticleEntity> page=new Page(currPage,pageSize);
            LambdaQueryWrapper<ArticleEntity> lambdaQueryWrapper=new LambdaQueryWrapper<>();
            lambdaQueryWrapper.eq(ArticleEntity::getIsDel,0);
            lambdaQueryWrapper.orderByDesc(ArticleEntity::getCreatedTime);
            if(StrUtil.isNotBlank(paramsDTO.getTitle())){
                lambdaQueryWrapper.like(ArticleEntity::getTitle,paramsDTO.getTitle());
            }
            this.page(page,lambdaQueryWrapper);
            pageUtils = new PageUtils(page);
        }catch (Exception e){
            log.error("查询文章异常",e);
        }
        return pageUtils;
    }
}
